package com.ulife.category.module.action;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.Navigator;
import com.alibaba.citrus.turbine.dataresolver.FormGroup;
import com.ulife.category.manager.PropertyManager;
import com.ulife.category.module.vo.PropertyVo;
import com.ulife.common.ErrorMessage;

public class PropertyAction {

	@Autowired
	private PropertyManager propertyManager;

	public void doAddProperty(@FormGroup("addproperty") PropertyVo propertyVo, Navigator nav, Context context) {
		int res = propertyManager.addPropertyManager(propertyVo);
		if (res > 0) {
			nav.redirectTo("cateLink").withTarget("propertylist").withParameter("catId", propertyVo.getcId().toString());
			return;
		} else {
			context.put("msg", ErrorMessage.SYSTEM_ERROR);
			nav.forwardTo("message");
			return;
		}
	}

	public void doDelProperty(@FormGroup("delproperty") PropertyVo propertyVo, Navigator nav, Context context) {
		int res = propertyManager.delPropertyManager(propertyVo);
		if (res <= 0) {
			context.put("msg", ErrorMessage.SYSTEM_ERROR);
			nav.forwardTo("message");
			return;
		}else{
			nav.redirectTo("cateLink").withTarget("propertylist").withParameter("catId", propertyVo.getcId().toString());
			return;
		}
	}
	
	public void doUpdateProperty(@FormGroup("updateproperty") PropertyVo propertyVo, Navigator nav, Context context) {
		propertyManager.updatePropertyManager(propertyVo);
		nav.redirectTo("cateLink").withTarget("propertylist").withParameter("catId", propertyVo.getcId().toString());
		return;
	}

}
